import java.util.Random;
import java.util.Scanner;

public class TestDemo {
    /**
     *  for循环
     * @param args
     */
    public static void main1(String[] args) {
//         打印 1 - 10 的数字
        int i = 0;
        for ( i = 1; i <= 10; i++) {
            System.out.println(i);
        }
    }

    public static void main2(String[] args) {
//        计算 1 - 100 的和
        int sum = 0;
        for (int i = 1; i <= 100 ; i++) {
            sum += i;
        }
        System.out.println(sum);
    }

    public static void main3(String[] args) {
//        计算 5 的阶乘
        int ret = 1;
        for (int i = 1; i <= 5; i++) {
            ret *= i;
        }
        System.out.println(ret);
    }

    public static void main4(String[] args) {
//        计算 1! + 2! + 3! + 4! + 5!
        int sum = 0;
        for (int i = 1; i <= 5; i++) {
            int ret = 1;
            for (int j = 1; j <= i; j++) {
                ret *= j;
            }
            sum += ret;
        }
        System.out.println(sum);
    }

    public static void main5(String[] args) {
//        使用 Scanner 读取字符串/整数/浮点数
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你的姓名：");
        String name = sc.nextLine();
        System.out.println("请输入你的年龄：");
        int age = sc.nextInt();
        System.out.println("请输入你的工资：");
        float salary = sc.nextFloat();
        System.out.println("你的信息如下：");
        System.out.println("姓名"+name+"\n"+"年龄"+age+"\n"+"工资"+salary);
    }

    public static void main6(String[] args) {
//        使用 Scanner 循环读取 N 个数字
        Scanner scan = new Scanner(System.in);
        double sum = 0;
        int num = 0;
        while (scan.hasNextDouble()) {
            double tmp = scan.nextDouble();
            sum += tmp;
            num++;
        }
        System.out.println("sum = "+sum);
        System.out.println("avg = "+sum/num);
    }

    public static void main7(String[] args) {
//        猜数字游戏
        Random random = new Random();
        Scanner scanner = new Scanner(System.in);
        int guess = random.nextInt(100);
        int count = 0;
        while (true){
            System.out.println("请输入要猜的数字（1——100）");
            int num = scanner.nextInt();
            if(num > guess) {
                System.out.println("猜大了");
                count++;
            }
            else if (num < guess) {
                System.out.println("猜小了");
                count++;
            }
            else {
                System.out.println("猜对了");
                count++;
                break;
            }
        }
        System.out.println("你猜中用了"+count+"次");
    }
}
